<template>
    <view class="page">
        <view style="position: fixed; top: 0;width: 100%;background-color: #ffffff;z-index: 11">
            <u-subsection :list="list" :current="curNow" @change="sectionChange" mode="subsection"></u-subsection>
        </view>
        <hm-filter :menuTop="60" :filterData="menuList" :defaultSelected="defaultSelected" :updateMenuName="true" @confirm="confirm" dataFormat="Object"></hm-filter>
        <view class="content" v-if="curNow===0">
            <user-list :user-list="userList" :is_pay="curNow" @refresh="refresh"></user-list>
        </view>
        <view class="content" v-if="curNow===1">
            <user-list :user-list="userList" :is_pay="curNow"></user-list>
        </view>
    </view>
</template>

<script>
    import HmFilter from "../../../components/hm-filter";
    import UserList from "./components/UserList";
    export default {
        name: "quality",
        components:{
            HmFilter,UserList
        },
        data() {
            return {
                list: ['优质客户', '客户池'],
                curNow: 0,
                defaultSelected: [],
                menuList:[
                    {
                        "name":'区域',
                        "type": 'hierarchy',
                        "submenu": [
                            {
                                "name": '附近',
                                "value": "raidus",
                                "submenu": [{
                                    "name": "不限",
                                    "value": ""
                                }, {
                                    "name": "1000m内",
                                    "value": "1000"
                                }, {
                                    "name": "3000m内",
                                    "value": "3000"
                                }, {
                                    "name": "5000m内",
                                    "value": "5000"
                                }]
                            },
                            {
                                "name": '区域',
                                "value": "area",
                                "submenu": [{
                                    "name": "不限",
                                    "value": ""
                                }]
                            },
                            // {
                            //     "name": '地铁',
                            //     "value": "",
                            //     "submenu": [{
                            //         "name": "不限",
                            //         "value": ""
                            //     }, {
                            //         "name": "1号线",
                            //         "value": ""
                            //     }, {
                            //         "name": "2号线",
                            //         "value": ""
                            //     }, {
                            //         "name": "3号线",
                            //         "value": ""
                            //     }, {
                            //         "name": "5号线",
                            //         "value": ""
                            //     }]
                            // },
                        ]
                    },
                    {
                        "name":'租金',
                        "type": 'radio',
                        "submenu": [{
                            "name": "请选择租金",
                            "submenu": [{
                                "name": "不限",
                                "value": ""
                            },{
                                "name": "500以下",
                                "value": "500"
                            },{
                                "name": "500-800",
                                "value": "500-800"
                            },{
                                "name": "800-1000",
                                "value": "800-1000"
                            },{
                                "name": "1000-1500",
                                "value": "1000-1500"
                            },{
                                "name": "1500-2000",
                                "value": "1500-2000"
                            },{
                                "name": "2000以上",
                                "value": "2000"
                            }]
                        }]
                    },
                    {
                        "name":'出租类型',
                        "type": 'radio',
                        "submenu": [{
                            "name": "类型",
                            "submenu": [
                                {
                                    'name': '精品公寓',
                                    'value': '1'
                                },
                                {
                                    'name': '分散式合租',
                                    'value': '2'
                                },
                                {
                                    'name': '分散式整租',
                                    'value': '3'
                                }
                            ]
                        }]
                    },
                    // {
                    //     "name":'筛选',
                    //     "type": 'filter',
                    //     "submenu": [{
                    //         "name": "房源特色",
                    //         "submenu": [{
                    //             "name": "独立阳台",
                    //             "value": ""
                    //         }, {
                    //             "name": "独卫",
                    //             "value": ""
                    //         }, {
                    //             "name": "独立厨房",
                    //             "value": ""
                    //         }, {
                    //             "name": "电梯",
                    //             "value": ""
                    //         }, {
                    //             "name": "朝南",
                    //             "value": ""
                    //         }, {
                    //             "name": "飘窗",
                    //             "value": ""
                    //         }, {
                    //             "name": "公共阳台",
                    //             "value": ""
                    //         }, {
                    //             "name": "公共厨房",
                    //             "value": ""
                    //         }, {
                    //             "name": "智能门锁",
                    //             "value": ""
                    //         }, {
                    //             "name": "免中介费",
                    //             "value": ""
                    //         }]
                    //     },
                    //     ]
                    // },
                ],
                areaList:[],
                filter:{
                    u_id: uni.getStorageSync('u_id'),
                    quality: 0
                },
                userList:[]
            }
        },
        onLoad: function() {
            uni.showLoading({title: '正在加载'});
            // 合肥各区
            uni.$u.http.get('/api.php/index/area_list?type=10').then(res => {
                this.areaList = res;
                for (let i = 0; i < res.length; i++) {
                    this.menuList[0].submenu[1].submenu.push({
                        'name': res[i].AREA_NAME,
                        'value': res[i].AREA_ID
                    });
                }
            });

            this.getUserList();
        },
        methods: {
            sectionChange(index) {
                uni.showLoading({title: '正在加载'});
                this.curNow = index;

                // this.filter.quality = index;

                this.getUserList();
            },
            //接收菜单结果
            confirm(e) {
                uni.showLoading({title: '正在加载'});

                this.filter = {
                    u_id: uni.getStorageSync('u_id'),
                    // quality: this.curNow
                };
                if (e.value[0][0] === 'area') {
                    for (let i = 0; i < this.areaList.length; i++) {
                        if (this.areaList[i].AREA_ID === e.value[0][1]){
                            this.filter.latitude = this.areaList[i].LAT;
                            this.filter.longitude = this.areaList[i].LNG;
                        }
                    }
                }

                if (e.value[0][0] === 'raidus') {
                    this.filter.raidus = e.value[0][1];
                }

                if (e.value[1][0].length > 0) {
                    this.filter.price = e.value[1][0][0];
                }

                if (e.value[2][0].length > 0) {
                    this.filter.lease_type = e.value[2][0][0];
                }

                this.getUserList();
            },

            getUserList(){
                uni.$u.http.get('/api.php/house/user_supervise', {params: this.filter}).then(res => {
                    uni.hideLoading();
                    this.userList = [];

                    for (let i = 0; i < res.data.length; i++) {
                        if (res.data[i].is_pay === parseInt(this.curNow)){
                            this.userList.push(res.data[i]);
                        }
                    }
                });
            },

            refresh(e){
                if (e.refresh){
                    this.curNow = 1;
                    this.getUserList();
                }
            },
        }
    }
</script>

<style scoped>
    .page {
        width: 100%;
        min-height: 100vh;
        background-color: #ffffff;
    }
    .content{
        padding: 150rpx 20rpx;
    }
</style>